package AgentTravel.Messages;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.*;

import AgentTravel.LogicObjects.City;
import AgentTravel.LogicObjects.CityVisit;
import AgentTravel.LogicObjects.Preferences;
import AgentTravel.LogicObjects.UserProfile;

// To jest wiadomosc przesylana z GUI do VisitorAgent
public class PlanMyTripMessage extends LoginMessage implements Serializable 
{
	private static final long serialVersionUID = 1L;
	
	private Calendar tripStartTime = GregorianCalendar.getInstance();
	private List<CityVisit> tripPlan = new ArrayList<CityVisit>();
	private Preferences preferences;
	private UserProfile myProfile;
	
	public PlanMyTripMessage(String user,String password)
	{
		super(user,password);
		System.out.println("Stworzono obiekt message");
	}

	/**
	 * @param tripStartTime the tripStartTime to set
	 */
	public void setTripStartTime(Calendar tripStartTime) {
		this.tripStartTime = tripStartTime;
	}

	public void setTripStartDate(Date date)
	{
		tripStartTime.setTime(date);
	}
	
	public Date getTripStartDate()
	{
		return tripStartTime.getTime();
	}

	/**
	 * @return the tripStartTime
	 */
	public Calendar getTripStartTime() {
		return tripStartTime;
	}

	public void setPreferences(Preferences preferences) {
		this.preferences = preferences;
	}


	public Preferences getPreferences() {
		return preferences;
	}


	public void setMyProfile(UserProfile myProfile) {
		this.myProfile = myProfile;
	}


	public UserProfile getMyProfile() {
		return myProfile;
	}

	/**
	 * @param tripPlan the tripPlan to set
	 */
	public void setTripPlan(List<CityVisit> tripPlan) {
		this.tripPlan = tripPlan;
	}

	/**
	 * @return the tripPlan
	 */
	public List<CityVisit> getTripPlan() {
		return tripPlan;
	}
	
	public void addCity(CityVisit c)
	{
		List<CityVisit> oldValue = tripPlan;
		tripPlan = new ArrayList<CityVisit>(tripPlan);
		tripPlan.add(c);
		firePropertyChange("tripPlan", oldValue, tripPlan);
	}
	
	public void removeCity(int index)
	{
		List<CityVisit> oldValue = tripPlan;
		tripPlan = new ArrayList<CityVisit>(tripPlan);
		tripPlan.remove(index);
		firePropertyChange("tripPlan", oldValue, tripPlan);
	}
	
	private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
			this);

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		propertyChangeSupport.addPropertyChangeListener(listener);
	}

	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		propertyChangeSupport.removePropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		propertyChangeSupport.removePropertyChangeListener(propertyName,
				listener);
	}

	protected void firePropertyChange(String propertyName, Object oldValue,
			Object newValue) {
		propertyChangeSupport.firePropertyChange(propertyName, oldValue,
				newValue);
	}
} 
